import React from 'react';
import ReactDom from 'react-dom';
//高阶组件其实是一个函数，传入一个组件，返回一个组件

function withLogger(OldComponent){
  return class extends React.Component {
    start = null
    componentWillMount(){
     this.start = Date.now();
    }
    componentDidMount(){
      console.log(Date.now() - this.start);
    }
    render(){
     return <OldComponent {...this.props}/>
    }
  }
}
class Hello extends React.Component {
  render(){
    return <div>hello {this.props.id}</div>
  }
}
let NewHello = withLogger(Hello);

ReactDom.render(
  <NewHello id='title'/>,
  document.getElementById('root')
)
